<%-- 
    Document   : CompleteThePurchase
    Created on : Apr 19, 2013, 8:58:48 AM
    Author     : Illya
--%>

<%@page import="com.charlie.beans.Users"%>
<%@include file="/header.jsp"%>

<script type="text/javascript">
    function cart_handle_item(item) {
        var itemId = item.getAttribute('id');
        var name = item.getAttribute('name');
        var amount = item.getAttribute('amount');
        var cost = item.getAttribute('cost');
        var tr = $('<tr></tr>');
        tr.append($('<td colspan="2"><a href="${pageContext.request.contextPath}/item/' + itemId + '">' + name + '</td>'));
        tr.append($('<td>(' + cost + '$ x' + amount + ')</td>'));
        tr.insertAfter('.cart_items_header');
    }
    function check_notify() {
        if ($(":checkbox").prop('checked')) {
            $('.email_line').show();
        } else {
            $('.email_line').hide();
        }
    }
    $(function() {
        check_notify();
        cart_query('items', 0, 0, null, cart_handle_item);
        var email_field = $('#email');
        if (email_field) {
            $("form").validationEngine();
            $(":checkbox").click(function() {
                check_notify();
                $("form").validationEngine('validate');
            });
        }
    });
</script>

<div style="width: 25%; float: left;">
    <jsp:include page="/blocks/conditionalLeftBar.jsp" />
</div>

<div style="width: 75%; float:  right;">
    <h2 class="content_title">Complete the purchase</h2>
    <div class="white_block">     
        <h3 style="line-height: 40px;"><b>Confirm the order</b></h3>
        <form method="post">
            <table>
                <tr class="cart_items_header">
                    <td>Selected guitars:</td>
                </tr>
                <tr>
                    <td><br>Selected warehouse:</td>
                    <td><br>${warehouse_addr}</td>
                </tr>
                <tr>
                    <td> Your location:</TD>
                    <td>${cart.getLocation()}</td>
                </tr>
                <tr class="email_line">
                    <td><br>Your email:</TD>
                    <td><br>
                        <%
                        if (user == null) { %>
                        <input type="email" name="email" id="email" class="validate[custom[email]]" value="${cart.getEmail()}" size="35"></td>
                        <% } else { 
                            out.print(user.getEmail());
                        } %>
                </tr>
                <tr>
                    <td colspan="2"><input type="checkbox" name="notify" id="notify" ${cart.getNotify() ? "checked" : ""}>Notify by e-mail about the order status</td>
                </tr>
                <tr>
                    <td><br>Price: ${items_cost} + ${delivery_cost} = ${total_price}$</td>
                </tr>
            </table>
            <p></p>
            <input type="hidden" name="warehouse_id" value="${cart.getWarehouse()}">
            <input type="hidden" name="destination" value="${destination_addr}">
            <input type="hidden" name="distance" value="${distance}">
            <input type="hidden" name="complete" value="1">
            <input type="submit" value="Checkout" style="margin-left: 500px;">
        </form>
    </div>
    
</div>
 
<jsp:include page="/footer.jsp" />
